package com.woniuxy01;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-10-24 9:27
 */
public class Test08 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("是否开始游戏y/n");
        String answer = scanner.next();
        int random;
        int num;
        int count;
        boolean flag;
        while (answer.equals("y")) {
            //归零:每次新开一局:随机数重新生成
            //归零:count计数，重新归零，赋值为1
            //归零：flag标志变量
            count=1;
            random = (int) (Math.random() * 100);
            flag=false;
            System.out.println("random="+random);
            do {
                System.out.println("输入你猜到的数字");
                num = scanner.nextInt();
                if (num > random) {
                    System.out.println("猜大了,剩余" + (5 - count) + "次机会");
                } else if (num < random) {
                    System.out.println("猜小了,剩余" + (5 - count) + "次机会");
                } else {
//                System.out.println("猜对了");
                    flag = true;
                    break;
                }
                //每猜一次，计数变量+1
                count++;
            } while (count <= 5);

//        if(count>5){
            //flase 没有猜对  !false就是true
            if (!flag) {
                System.out.println("5次机会用完了，挑战失败");
            } else {
                System.out.println("猜对了");
            }
            System.out.println("是否继续游戏y/n");
            answer=scanner.next();
        }
        System.out.println("程序结束");


    }
}
